package com.ruoyi.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.domain.BrandInfo;
import com.ruoyi.service.IBrandInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 品牌
 */
@RestController
@RequestMapping("/webshop/brandInfo")
public class BrandInfoController extends BaseController{
    @Autowired
    private IBrandInfoService brandInfoService;

    // 全查
    @GetMapping("/list")
    public List<BrandInfo> list() {
        List<BrandInfo> list = brandInfoService.list();
        return list;
    }
    @GetMapping("/listByConeAll")
    public List<BrandInfo> listByCone() {
        List<BrandInfo> list = brandInfoService.listByConeAll();
        return list;
    }
    @GetMapping("/listByCone/{id}")
    public List<BrandInfo> listByCone(@PathVariable Long id) {
        List<BrandInfo> list = brandInfoService.listByCone(id);
        return list;
    }

    @GetMapping("/listForPage")
    public TableDataInfo listForPage(BrandInfo brandInfo) {
        System.out.println("brandInfo = " + brandInfo);
        startPage();
        List<BrandInfo> list = brandInfoService.listForPage(brandInfo);

        return getDataTable(list);
    }

    // 根据id查一条
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        System.out.println("id = " + id);
        BrandInfo brandInfo = brandInfoService.getById(id);
        return success(brandInfo);
    }

    // 添加
    @PostMapping()
    public AjaxResult add(@RequestBody BrandInfo brandInfo) {
        System.out.println("brandInfo = " + brandInfo);
        int add = brandInfoService.save(brandInfo);
        return toAjax(add);
    }

    // 修改
    @PutMapping()
    public AjaxResult edit(@RequestBody BrandInfo brandInfo) {
        System.out.println("brandInfo = " + brandInfo);
        int edit = brandInfoService.updateById(brandInfo);
        return toAjax(edit);
    }

    // 根据ids删除多条
    @DeleteMapping("/{ids}")
    public AjaxResult deleteMany(@PathVariable Long[] ids) {
        System.out.println("ids = " + ids);
        int delete = brandInfoService.removeByIds(ids);
        return toAjax(delete);
    }
}
